﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace WeChat.Controls
{
    /// <summary>
    /// 切换按钮
    /// </summary>
    public class CheckButton : RadioButton
    {
        public static readonly DependencyProperty CheckedImageProperty = DependencyProperty.Register("CheckedImage", typeof(Geometry), typeof(CheckButton), new PropertyMetadata(null, OnPropertyChanged));

        /// <summary>
        /// 图标
        /// </summary>
        public Geometry CheckedImage
        {
            get { return (Geometry)GetValue(CheckedImageProperty); }
            set { SetValue(CheckedImageProperty, value); }
        }

        public static readonly DependencyProperty UnCheckImageProperty = DependencyProperty.Register("UnCheckImage", typeof(Geometry), typeof(CheckButton), new PropertyMetadata(null, OnPropertyChanged));

        /// <summary>
        /// 图标
        /// </summary>
        public Geometry UnCheckImage
        {
            get { return (Geometry)GetValue(UnCheckImageProperty); }
            set { SetValue(UnCheckImageProperty, value); }
        }

        public static readonly DependencyProperty ImageWidthProperty = DependencyProperty.Register("ImageWidth", typeof(double), typeof(CheckButton), new PropertyMetadata(12.0));

        /// <summary>
        /// 图标宽度
        /// </summary>
        public double ImageWidth
        {
            get { return (double)GetValue(ImageWidthProperty); }
            set { SetValue(ImageWidthProperty, value); }
        }

        public static readonly DependencyProperty ImageHeightProperty = DependencyProperty.Register("ImageHeight", typeof(double), typeof(CheckButton), new PropertyMetadata(12.0));

        /// <summary>
        /// 图标高度
        /// </summary>
        public double ImageHeight
        {
            get { return (double)GetValue(ImageHeightProperty); }
            set { SetValue(ImageHeightProperty, value); }
        }

        private static void OnPropertyChanged(DependencyObject dependency, DependencyPropertyChangedEventArgs args)
        {
            CheckButton button = dependency as CheckButton;
            if (args.Property.Name.Equals("CheckedImage"))
                button.CheckedImage = (Geometry)args.NewValue;
            else if (args.Property.Name.Equals("UnCheckImage"))
                button.UnCheckImage = (Geometry)args.NewValue;
        }
    }
}
